home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 17 / AMIGAplus Sonderheft 17 (1999)(ICP)(DE)[!].iso / Rexx / UpdateRatings.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-26  |  6KB  |  215 lines

  1. /*RX
  2.     $RCSFile: $
  3.     $Revision: 2.1 $
  4.     $Date: 1993/12/12 13:22:15 $
  5.  
  6.     This program is intended to support the use of a tournament file as
  7.     a database. It should be called from Chaos itself to update the
  8.     DWZ numbers in a previously saved tournament file.
  9.  
  10.     Usage: UpdateRatings [filename]
  11.  
  12.     <filename> is the name of a database file. This argument is not
  13.     required if you have RequestFile or a similar command: The script
  14.     brings up a requester to select a file in that case. (The commands
  15.     name can be changed below in the script. However, it must write the
  16.     filename to stdout.) I don't know, if RequestFile is available below
  17.     of Workbench 39, sorry.
  18.  
  19.     Important notes:
  20.     - This script must not be used, if Chaos isn't ready to receive
  21.       commands. Chaos shows that it is ready by enabling the menu bar in
  22.       its main window. The best way to ensure this, is to call it from
  23.       the menu bar itself by including the script into s/ChaosMenu.
  24.     - It is assumed, that the player names in the tournament and in the
  25.       database file are identical. The best way to ensure this is, to
  26.       use the menu item "Import".
  27. */
  28.  
  29.  
  30. /*
  31.     Setting up global variables
  32. */
  33. DWZFileName        = "t:UpdateRatings.DWZoutput";
  34. PlayerListFileName    = "t:UpdateRatings.PlayerList";
  35. CurrentTournamentName    = "t:CurrentTournament.cdat";
  36.  
  37.  
  38.  
  39. /*
  40.     Parsing command line arguments.
  41. */
  42. PARSE ARG FileName
  43. IF  FileName == "?" THEN DO
  44.     SAY("Usage: UpdateRatings [filename]");
  45.     SAY("");
  46.     SAY("Uses Chaos to create a listing of the current tournaments DWZ numbers.");
  47.     SAY("These numbers will be updated in the tournament file <filename>.");
  48.     SAY("If filename isn't present, ",RequestCommand," will be used to");
  49.     SAY("select a file.");
  50.     exit(0);
  51. END;
  52. IF FileName == "" THEN DO
  53.     ADDRESS COMMAND RequestFile ">t:UpdateRatings.FileName #?.cdat";
  54.     IF ~OPEN(.FileNameFile, "t:UpdateRatings.FileName", "Read") THEN DO
  55.     SAY ("Cannot get database name.");
  56.     EXIT(10);
  57.     END;
  58.     FileName = READLN(.FileNameFile);
  59.     IF    ~CLOSE(.FileNameFile)  THEN DO
  60.     SAY("Cannot get database name.");
  61.     EXIT(10);
  62.     END;
  63.     IF FileName == ""  THEN DO
  64.     EXIT(0);    /*  User selected "Cancel"  */
  65.     END;
  66. END;
  67.  
  68.  
  69. /*
  70.     Let Chaos write the list of DWZ numbers.
  71. */
  72. ADDRESS "CHAOS.1"   "DWZReport "DWZFileName
  73. IF  RC ~= 0  THEN DO
  74.     SAY("Chaos: Cannot create table. (Chaos not ready, not running or no pairings?)");
  75.     EXIT(10);
  76. END;
  77.  
  78.  
  79. /*
  80.     Open the list of DWZ numbers.
  81. */
  82. IF ~OPEN(.DWZFile, DWZFileName, "Read") THEN DO
  83.     SAY ("Cannot open DWZ list.");
  84.     EXIT(10)
  85. END;
  86.  
  87.  
  88. /*
  89.     Read the table header.
  90. */
  91. Line = READLN(.DWZFile);                /*  Skip the tournament name.   */
  92. Line = READLN(.DWZFile);                /*  Skip empty line.            */
  93. Line = READLN(.DWZFile);                /*  Skip report title.          */
  94. Line = READLN(.DWZFile);                /*  Skip empty line.            */
  95. Line = READLN(.DWZFile);                /*  Skip page header. (2 lines) */
  96. Line = READLN(.DWZFile);
  97. Line = READLN(.DWZFile);                /*  Skip empty line.            */
  98.  
  99.  
  100. /*
  101.     Read the players.
  102. */
  103. NumPlayers = 0;
  104. DO UNTIL EOF(.DWZFile);
  105.     Line = READLN(.DWZFile);
  106.     IF ~EOF(.DWZFILE) THEN DO
  107.     NumPlayers = NumPlayers + 1;
  108.     /*
  109.         Names (and the Chessclubs) may contain blanks and hence must be
  110.         handled in a different manner than numbers.
  111.     */
  112.     Players.NumPlayers.Name = STRIP(SUBSTR(Line, 1, 30), 'B');
  113.     Players.NumPlayers.DWZ = WORD(SUBSTR(Line, 31), 6);
  114.     Line = READLN(.DWZFile);            /*  Skip birthday line.     */
  115.     END;
  116. END;
  117.  
  118.  
  119. /*
  120.     Close the DWZ list.
  121. */
  122. IF  ~CLOSE(.DWZFile)  THEN DO
  123.     SAY("Cannot close DWZ list.");
  124.     EXIT(10);
  125. END;
  126.  
  127.  
  128. /*
  129.     Let Chaos save the current tournament to ensure, that we can load
  130.     another and restore the current state.
  131. */
  132. ADDRESS "CHAOS.1" "SaveTournament "CurrentTournamentName
  133.  
  134.  
  135. /*
  136.     Let Chaos load the database file.
  137. */
  138. ADDRESS "CHAOS.1" "LoadTournament "FileName
  139.  
  140.  
  141. /*
  142.     Let Chaos write the list of players to find, which players should be
  143.     updated.
  144. */
  145. ADDRESS "CHAOS.1" "PlayerList "PlayerListFileName" short"
  146.  
  147.  
  148. /*
  149.     Open the list of players.
  150. */
  151. IF ~OPEN(.PlayerListFile, PlayerListFileName, "Read") THEN DO
  152.     SAY ("Cannot open player list.");
  153.     EXIT(10)
  154. END;
  155.  
  156.  
  157. /*
  158.     Read the player list header.
  159. */
  160. Line = READLN(.PlayerListFile);         /*  Skip the tournament name.   */
  161. Line = READLN(.PlayerListFile);         /*  Skip empty line.            */
  162. Line = READLN(.PlayerListFile);         /*  Skip list title.            */
  163. Line = READLN(.PlayerListFile);         /*  Skip empty line.            */
  164. Line = READLN(.PlayerListFile);         /*  Skip page header.           */
  165. Line = READLN(.PlayerListFile);         /*  Skip empty line.            */
  166.  
  167.  
  168. /*
  169.     Read the players and update them, if they were present in the DWZ
  170.     report.
  171.     (Sorry, this is not an example of very good programming. We could use
  172.     the fact, that both lists are sorted alphabetically in order to enhance
  173.     speed. But I doubt, we would win that much.)
  174. */
  175. DO UNTIL EOF(.PlayerListFile);
  176.     Line = READLN(.PlayerListFile);
  177.     IF    ~EOF(.PlayerListFile)  THEN DO
  178.     CurrentPlayerName = STRIP(SUBSTR(Line, 6, 30), 'B');
  179.     /*
  180.         Check, if we find the current player in the DWZ report.
  181.     */
  182.     DO  i = 1   TO    NumPlayers;
  183.         IF    CurrentPlayerName == Players.i.Name  THEN  DO
  184.         ADDRESS "CHAOS.1" 'ModifyPlayer "'CurrentPlayerName'" RATING 'Players.i.DWZ
  185.         END;
  186.     END;
  187.     END;
  188. END;
  189.  
  190.  
  191. /*
  192.     Close the player list.
  193. */
  194. IF  ~CLOSE(.PlayerListFile)  THEN DO
  195.     SAY("Cannot close player list. Current tournament is saved in "CurrentTournamentName);
  196.     EXIT(10);
  197. END;
  198.  
  199.  
  200. /*
  201.     Save the database.
  202. */
  203. ADDRESS "CHAOS.1" "SaveTournament "FileName
  204.  
  205.  
  206. /*
  207.     Restore the current tournament.
  208. */
  209. ADDRESS "CHAOS.1" "LoadTournament "CurrentTournamentName
  210.  
  211.  
  212. /*
  213.     Well, guys, thats it! :-)
  214. */
  215.